<?php
define('IN_ADMINCP', TRUE);
define('ADMINCP_PATH', dirname(__FILE__));
define('APP_PATH', dirname(ADMINCP_PATH));
require APP_PATH . '/app.php';
$uri = $_G['gp_referer'] ? $_G['gp_referer'] : './index.php';
//var_dump($_G['gp_referer']);exit;
if ( Session::Get('adminid') ){
	redirect($uri);
}
$account = new admincp_account;
$mobile = checkmobile();
// var_dump(Session::Get('adminid'));die;
if ( is_post() || $account->initCode() ){
	if ( $admin = $account->login() ){
		if ( AJAX ){
			$expire = 7 * 86400;
			$admin['avatar'] = avatar($admin['avatar']);
			$admin['authcode'] = ($mobile ? authcode($admin['password'], 'ENCODE', 'heivr-login-auth', $expire) : '');
			$admin['redirectURL'] = $_GET['referer'] ? $_GET['referer'] : './';
			jsonp($admin, 'data', 0);
		}
		
		redirect($uri);
	}
}
if( !AJAX ){
	include template('admin_login');
}
